//
//  YWAssignAndCancelPostTroubleCell.m
//  maintain
//
//  Created by kyo on 17/2/10.
//  Copyright © 2017年 ewin. All rights reserved.
//

#import "YWAssignAndCancelPostTroubleCell.h"
#import "UIColor+CustomColors.h"
#import "Masonry.h"
#import "YWMacro.h"

@interface YWAssignAndCancelPostTroubleCell()
@property (nonatomic, strong) UIButton *assignButton;
@property (nonatomic, strong) UIButton *cancelPostTroubleButton;
@end

@implementation YWAssignAndCancelPostTroubleCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.layer.shouldRasterize = YES;
        self.layer.rasterizationScale = [UIScreen mainScreen].scale;
        [self setUpSubviews];
        self.contentView.backgroundColor = [UIColor customBackgroudColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.separatorInset = UIEdgeInsetsMake(0, SCREEN_WIDTH, 0, 0);
    }
    return self;
}

- (void) setUpSubviews {
    UIView *superview = self.contentView;
    
    [self.assignButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(superview).offset(10);
        make.left.mas_equalTo(superview).offset(20);
        make.right.mas_equalTo(superview).offset(-20);
        make.height.mas_equalTo(kButtonH);
    }];
    [self.cancelPostTroubleButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_assignButton.mas_bottom).offset(10);
        make.left.mas_equalTo(_assignButton.mas_left);
        make.right.mas_equalTo(_assignButton.mas_right);
        make.height.mas_equalTo(kButtonH);
        make.bottom.mas_equalTo(superview.mas_bottom).offset(-10);
    }];
}

- (UIButton *)assignButton{
    if (!_assignButton) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
        button.backgroundColor = [UIColor customBlueColor];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [button setTitle:@"分配" forState:UIControlStateNormal];
        button.layer.borderColor = [UIColor customBlueColor].CGColor;
        button.layer.borderWidth = 1.0;
        button.layer.masksToBounds = YES;
        button.layer.cornerRadius = 4.0;
        button.titleLabel.font = KTitleFont;
        [button addTarget:self action:@selector(clickAssignButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
        _assignButton = button;
        [self.contentView addSubview:_assignButton];
    }
    return _assignButton;
}

- (UIButton *)cancelPostTroubleButton{
    if (!_cancelPostTroubleButton) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
        button.backgroundColor = [UIColor customRedColor];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [button setTitle:@"撤回报障" forState:UIControlStateNormal];
        button.layer.borderColor = [UIColor customRedColor].CGColor;
        button.layer.borderWidth = 1.0;
        button.layer.masksToBounds = YES;
        button.layer.cornerRadius = 4.0;
        button.titleLabel.font = KTitleFont;
        [button addTarget:self action:@selector(clickCancelPostTroubleButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
        _cancelPostTroubleButton = button;
        [self.contentView addSubview:_cancelPostTroubleButton];
    }
    return _cancelPostTroubleButton;
}
- (void)clickAssignButtonEvent:(UIButton*)sender{
    if ([self.delegate respondsToSelector:@selector(clickAssignOrCancelPostTroubleButtonEventWithTitle:)]) {
        [self.delegate clickAssignOrCancelPostTroubleButtonEventWithTitle:@"分配"];
    }
}

- (void)clickCancelPostTroubleButtonEvent:(UIButton*)sender{
    if ([self.delegate respondsToSelector:@selector(clickAssignOrCancelPostTroubleButtonEventWithTitle:)]) {
        [self.delegate clickAssignOrCancelPostTroubleButtonEventWithTitle:@"撤回报障"];
    }
}

@end
